from datetime import datetime
from typing import Optional
from pydantic import BaseModel

class WalletBase(BaseModel):
    user_id: str
    balance: float

class WalletCreate(WalletBase):
    pass

class WalletUpdate(BaseModel):
    balance: Optional[float] = None

class Wallet(WalletBase):
    id: str
    created_at: datetime
    updated_at: datetime

class RedPacketBase(BaseModel):
    sender_id: str
    receiver_id: str
    amount: float
    status: str  # 'sent', 'claimed', 'expired'

class RedPacketCreate(RedPacketBase):
    pass

class RedPacketUpdate(BaseModel):
    status: Optional[str] = None
    claimed_at: Optional[datetime] = None

class RedPacket(RedPacketBase):
    id: str
    created_at: datetime
    claimed_at: Optional[datetime] = None

class TransactionBase(BaseModel):
    user_id: str
    type: str  # 'recharge', 'withdraw', 'send_red_packet', 'claim_red_packet', 'transfer_out', 'transfer_in'
    amount: float
    balance_after: float
    description: str

class TransactionCreate(TransactionBase):
    pass

class TransactionUpdate(BaseModel):
    pass

class Transaction(TransactionBase):
    id: str
    related_id: Optional[str] = None
    created_at: datetime